<template>
	<sc-table-select :class="{'custom-org-el-select-close':orgcodevalue.length<=1}"  
		placeholder="---请选择---"
		ref="tableselect"
		v-model="orgcodevalue"
		style="width: 300px"
		:pageId="pageId"
		:userCode="userCode"
		:purviewType="purviewType"
		:attrList="attrList"
		:valueList="valueList"
		:queryList="queryList"
		:orderList="orderList"
		:table-width="640"
		:multiple="multiple"
		selectType="org"
		collapse-tags
		collapse-tags-tooltip
		:props="props"
		:selectKeyValue="selectKeyValue"
		@change="change"
		@remove-tag="removeTag"
	>
		<!-- collapse-tags
    collapse-tags-tooltip -->
		<template #header="{}">
			<el-form :inline="true">
				<el-row :gutter="5"
					><el-col :span="5">
						<el-input
							v-model="queryList.Code"
							placeholder="请输入编码"
							style="width: 125px"
						></el-input></el-col
					><el-col :span="5">
						<el-input
							v-model="queryList.Name"
							placeholder="请输入名称"
							style="width: 125px"
						></el-input> </el-col
					><el-col :span="5"
						><el-select
							v-model="queryList.TypeCode"
							placeholder="请选择类型"
							style="width: 125px"
							clearable
							:teleported="false"
						>
							<el-option
								label="---请选择---"
								value=""
							></el-option>
							<el-option label="直营店" value="01"></el-option>
							<el-option
								label="加盟店"
								value="02"
							></el-option> </el-select></el-col
					><el-col :span="5">
						<el-select
							v-model="queryList.State"
							placeholder="请选择状态"
							clearable
							:teleported="false"
							style="width: 125px"
						>
							<el-option label="---请选择状态---" value="" />
							<el-option label="禁用" value="0" />
							<el-option
								label="启用"
								value="1"
							/> </el-select></el-col
					><el-col :span="4">
						<el-button
							type="primary"
							@click="$refs.tableselect.getData()"
							>查询</el-button
						></el-col
					></el-row
				>
			</el-form>
		</template>
		<el-table-column
			prop="OrgCode"
			label="机构编码"
			width="100"
		></el-table-column>
		<el-table-column
			prop="OrgName"
			label="机构名称"
			width="150"
		></el-table-column>
		<el-table-column
			prop="ParentName"
			label="父级"
			width="150"
		></el-table-column>
		<el-table-column
			prop="OrgTypeName"
			label="类型"
			width="120"
		></el-table-column>
		<el-table-column
			prop="State"
			label="状态"
			width="100"
		></el-table-column>
	</sc-table-select>
</template>

<script>
import tool from "@/utils/tool";
import bus from "@/utils/mitt";
export default {
	name: "orgselect",
	props: {
		pageId: { type: String, default: "" },
		multiple: { type: Boolean, default: true },
		userCode: { type: String, default: "super" },
		purviewType: { type: String, default: "super" },
		selectKeyValue: { type: String, default: "Code" },
	},
	data() {
		return {
			hideClearBtn: true,
			attrList: {
				//Name: "Organize",
				Name: "PageOrg",
				UseDistinct: true,
				OrgCode: "",
				UseBackUp: false,
				UseGroup: false,
			},
			valueList: {
				Code: "OrgCode",
				Name: "OrgName",
				ParentName: "ParentName",
				OrgTypeName: "OrgTypeName",
				State: "State",
				PageId: "",
				PurviewId:"",
				//不同角色绑定的页面一样会导致数据重复
				//RoleCode: "",
				UserCode: "",
			},
			queryList: {
				Code: "",
				Name: "",
				OrgTypeCode: "",
				Visible: "1",
				// InLocal:"0",
				State: "",
				PageId: this.pageId,
				UserCode: this.userCode,
				purviewType: "super",
			},
			//apiObj: this.$API.demo.page,
			params: {
				name: "demoName",
			},
			orgcodevalue: [],
			props: {
				label: "OrgName",
				value: "OrgCode",
				keyword: "keyword",
			},
			formatType(row, column) {
				// eslint-disable-next-line no-debugger
				////debugger;
				console.log(row, column);
				switch (row.TypeCode) {
					case "01":
						return "直营店";
					case "02":
						return "加盟店";
					default:
						return "";
				}
			},
			lastOrgVal:[]
		};
	},
	computed: {},
	mounted() {},
	methods: {
		//值变化
		change(val) {
			debugger
			let userInfo = tool.data.get("USER_INFO");
			// if(this.multiple){
			// 	userInfo.currentOrgCode = val.map(obj => obj.OrgCode).join(',');
            // 	userInfo.currentOrgName = val.map(obj => obj.OrgName).join(',');
			// }else{
			// 	userInfo.currentOrgCode = val.OrgCode;
			// 	userInfo.currentOrgName = val.OrgName;
			// }
			// bus.emit("changeOrg", { orgCode: userInfo.currentOrgCode , orgName: userInfo.currentOrgName  });
            // this.$TOOL.data.set("USER_INFO", userInfo);
			let userCode = userInfo.userCode;
			if (userCode == "admin" || userCode == "super")
				this.$emit("fatherMethod", val);
			else {
				if (Array.isArray(val)) {
					if (val.length == 0) {
						this.$alert("请选择要操作的机构", "提示", {
							type: "warn",
						});
						this.$emit("fatherMethod", []);
					} else this.$emit("fatherMethod", val);
				} else {
					if (val) {
						this.$emit("fatherMethod", val);
					}
				}
			}
			//this.$message("change事件，返回详情查看控制台1");
		},
		// removeTag(val){
		// 	debugger;
		// 	if(this.orgcodevalue.length==0){
		// 		this.orgcodevalue=[{OrgCode:val.OrgCode,OrgName:val.OrgName}];
		// 		this.$emit("fatherMethod", this.orgcodevalue)
		// 	}
		// }
	},
};
</script>

<style>
.custom-org-el-select-close .el-tag__close {
  display: none !important;
}
</style>
